/*
 * timer.c
 *
 *  Created on: Mar 10, 2012
 *      Author: Christian
 */

#include "timer.h"

timer* timer_init() {
	timer* timer_ptr = (timer*) malloc(sizeof(timer));
	timer_ptr->timer_limit = SLEEP_TIMER;
	timer_ptr->timer_interrupt = false;
//	usleep(SLEEP_TIMER);
	return timer_ptr;
}

void* timer_start(void* timer_ptr) {
	timer* t_ptr = (timer*) timer_ptr;
	while (t_ptr->timer_interrupt == false) {
		for (int i = 0; i < SLEEP_TIMER; i++) {
			if (i == SLEEP_TIMER-1) {
				t_ptr->timer_interrupt = true;
			}
		}
		while (t_ptr->timer_interrupt == true) {
			pause();
		}
	}
	return NULL;
}

void pause() {
	int i;
	for (i = 0; i < 200000; i++);
}
